package com.vgemv.jsutilitysdk.activity.jsloglistactivity;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vgemv.jsutilitysdk.geometry.JsGeometryManager;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemView.JsMenuItemView;
import com.vgemv.jsutilitysdk.Menu.JsMenuView.JsMenuItemVm.JsMenuItemVm;

public class JsLogFileItemView extends JsMenuItemView {

    private TextView mTv_title;
    private TextView mTv_index;
    private RelativeLayout mRl;
    public JsLogFileItemView(Context context) {
        super(context);

        mRl = new RelativeLayout(context);
        addView(mRl);

        mTv_index = new TextView(context);
        mTv_index.setId(View.generateViewId());
        mTv_index.setTextAlignment(TEXT_ALIGNMENT_CENTER);
        mTv_index.setGravity(Gravity.CENTER);
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(JsGeometryManager.pixelFromDp(30), ViewGroup.LayoutParams.MATCH_PARENT);
        mRl.addView(mTv_index,lp);
        mTv_index.setBackgroundColor(Color.rgb(200,100,100));
        mTv_index.setTextSize(JsGeometryManager.pixelFromDp(6));

        mTv_title = new TextView(context);
        mTv_title.setId(View.generateViewId());
        mTv_title.setGravity(Gravity.CENTER_VERTICAL|Gravity.LEFT);
        RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
        rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        rlp.addRule(RelativeLayout.RIGHT_OF,mTv_index.getId());
        rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        rlp.setMargins(JsGeometryManager.pixelFromDp(20),0,0,0);
        mRl.addView(mTv_title,rlp);
        mTv_title.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        mTv_title.setTextSize(JsGeometryManager.pixelFromDp(7));

    }

    /**
     * 子类显示ui的函数,会重复调用.根据itemVm来显示内容.
     *
     * @param context
     * @param itemVm
     */
    @Override
    public void customSetVm(Context context, JsMenuItemVm itemVm) {
        JsLogFileItemVm fileVm = (JsLogFileItemVm)itemVm;
        JsLogFileItemModel model = (JsLogFileItemModel) fileVm.currentModel();
        mTv_title.setText(model.getFileName());
        mTv_index.setText(String.format("%d",itemVm.index));
    }
}
